﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using DotNetOpenAuth.Messaging;
using Microsoft.Ajax.Utilities;
using PagedList;
using QAS.Nekorama.Models;


namespace QAS.Nekorama.Logic
{
    public class QuestionLogic
    {
        static public IQueryable<Question> Search(string searchString)
        {
            Entities db = new Entities();
            var questionList = from q in db.Questions
                               select q;
            string tagKey;
            string tagString = " "; //string contain all tags get from search text box: "#tag1, #tag2, #tag3..."
            string textKey = " "; //search text key
            //char[] delimiter = {':'};
            //string[] words = searchString.Trim().Split(delimiter);
            //words[0] = tagString;
            //foreach (var word in words)
            //{
            //    textKey = textKey + " " + word;
            //}

            if (searchString.StartsWith("#"))
                {
                    tagKey = searchString.Substring(1);
                    questionList = questionList.Where(q => q.TagName1.Equals(tagKey)
                                                           || q.TagName2.Equals(tagKey)
                                                           || q.TagName3.Equals(tagKey)
                                                           || q.TagName4.Equals(tagKey)
                                                           || q.TagName5.Equals(tagKey));
                }
            else //search full text
            {
                
            }
            return questionList;
        }
    }
}